//
//  OffLineProgressView.swift
//  SmartPenSwift
//
//  Created by tql on 2021/3/9.
//

import UIKit

class OffLineProgressView: UIView {

    
    typealias CallbackBlock = (_ pauseOrGoOn : Bool) -> ()
    var pauseDownloadBlock : CallbackBlock?
    
    var progress : CGFloat = 0{
        willSet{
            self.cView.progress = newValue
        }
    }
    
    private var pauseHidevar : Bool = false
    var hidepause : Bool  {
        get{
            return pauseHidevar
        }set{
            pauseHidevar = newValue
            
            self.pOrGonBtn.isHidden = newValue
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
//        self.progress = 0
        self.backgroundColor = .white
        self.initUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    lazy var cView : CircleView = {
        let view : CircleView = CircleView()
        view.frame = CGRect(x: 0, y: 0, width: kScreenWidth * 100 / 375.0, height: kScreenWidth * 100 / 375.0)
        return view
    }()
    lazy var pOrGonBtn : UIButton = {
        let btn : UIButton = UIButton.init()
        btn.setTitleColor(UIColor(hex: "8492A6"), for: .normal)
        btn.setTitle("pause", for: .normal)
        btn.setTitle("go on", for: .selected)
        btn.titleLabel?.font  = UIFont.systemFont(ofSize: 16)
        btn.addTarget(self, action: #selector(btnclick(_ :)), for: .touchUpInside)
        return btn
    }()
    
    @objc func btnclick(_ btn : UIButton){
        self.pOrGonBtn.isSelected = !self.pOrGonBtn.isSelected
        if  self.pauseDownloadBlock != nil {
            self.pauseDownloadBlock!(self.pOrGonBtn.isSelected)
        }
    }
    func initUI() -> Void {
        self.addSubview(self.cView)
        self.cView.snp.makeConstraints { (make) in
            make.top.equalTo(self).offset(kScreenWidth * 30 / 375.0)
            make.height.width.equalTo(kScreenWidth * 100 / 375.0)
            make.centerX.equalTo(self)
        }
        
        self.addSubview(self.pOrGonBtn)
        self.pOrGonBtn.snp.makeConstraints { (make) in
            make.left.right.equalTo(self)
            make.height.equalTo(kScreenWidth * 45 / 375)
            make.bottom.equalTo(self)
        }
        
        
        
    }
    

}
